package Hot100.Tree;

public class diameterOfBinaryTree {
    public static void main(String[] args) {
        int[] value = {1,25};
        BinaryTree binaryTree = new BinaryTree();
        binaryTree.insert(value);
        diameterOfBinaryTree diameterOfBinaryTree = new diameterOfBinaryTree();
        System.out.println(diameterOfBinaryTree.diameterOfBinaryTree(binaryTree.root));
    }
    int ans ;
    public int diameterOfBinaryTree(TreeNode root) {
        if(root == null)
            return 0;
        ans = 1;
        inorder(root);
        return ans-1;
    }
    public int inorder(TreeNode root){
        if(root == null)
            return 0;
        int left = inorder(root.left);
        int right = inorder(root.right);
        ans = Math.max(ans,left+right+1);
        return Math.max(left,right) + 1;
    }
}
